package megrez.common.core.util;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * 计时器
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
public class Timer {
    private long start = System.nanoTime();

    public Duration duration() {
        return Duration.ofMillis(TimeUnit.NANOSECONDS.toMillis(
                System.nanoTime() - start));
    }

    public static Duration duration(Runnable test) {
        Timer timer = new Timer();
        test.run();
        return timer.duration();
    }    
}
